package io.renren.modules.work.service.impl;

import io.renren.common.utils.R;
import io.renren.vo.PicDTO;
import io.renren.vo.PicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.work.dao.ScFileDao;
import io.renren.modules.work.entity.ScFileEntity;
import io.renren.modules.work.service.ScFileService;


@Service("scFileService")
public class ScFileServiceImpl extends ServiceImpl<ScFileDao, ScFileEntity> implements ScFileService {

    @Autowired
    private ScFileService scFileService;
    @Value("${ImgServerIP}")
    private String imgServerIP;
    @Value("${ImgServerPort}")
    private String imgServerPort;
    @Value("${ImgUrl}")
    private String imgUrl;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ScFileEntity> page = this.page(
                new Query<ScFileEntity>().getPage(params),
                new QueryWrapper<ScFileEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<PicVo> getPic(PicDTO picDTO) {
        List<PicVo> picVos = new ArrayList<>();
        String projectdtlid = picDTO.getProjectdtlid();
        int fileType = picDTO.getFileType();
        QueryWrapper<ScFileEntity> scFileEntityQueryWrapper = new QueryWrapper<>();
        scFileEntityQueryWrapper.eq("filetype",fileType);
        scFileEntityQueryWrapper.eq("projectdtlid",projectdtlid);
        List<ScFileEntity> list = scFileService.list(scFileEntityQueryWrapper);
        if(list.size()>0){
            for (ScFileEntity scFileEntity : list) {
                PicVo picVo = new PicVo();
                picVo.setFileId(scFileEntity.getFileid());
                picVo.setName(scFileEntity.getRealfilename());
                picVo.setUrl(imgUrl+scFileEntity.getFilename());
                picVo.setRealName(scFileEntity.getFilename());
                picVos.add(picVo);
            }
        }
        return picVos;
    }

}